/*
 * MainEntryPoint.java
 *
 * Created on September 22, 2008, 12:31 PM
 */
package org.ido.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.RootPanel;
import org.ido.client.components.SimpleDialog;

/**
 *
 * @author greenido
 */
public class MainEntryPoint implements EntryPoint {

    private MenuBar mainMenuBar;
    private MainPanel mainPanel;

    /** Creates a new instance of MainEntryPoint */
    public MainEntryPoint() {
    }

    private void createMenuBar() {
        MenuBar gameMenu = new MenuBar(true);
        gameMenu.addItem("New Game", new Command() {

            public void execute() {
                if (mainPanel.isIsItFinished()) {
                    cleanUI();
                    onModuleLoad();
                } else {
                    String[] buttons = {"Yep", "No way!"};
                    SimpleDialog sd = new SimpleDialog("Are you sure?", "Do you feel like trashing this game for good?", buttons);
                    sd.show();
                    if (sd.getAnswer() == 0) {
                        cleanUI();
                        onModuleLoad();
                    }
                }
            }
        });

        gameMenu.addItem("Rest Score", new Command() {

            public void execute() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        });

        gameMenu.addItem("Tell Your Friend", new Command() {

            public void execute() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        });

        MenuBar helpMenu = new MenuBar(true);
        helpMenu.addItem("Cheat Sheat", new Command() {

            public void execute() {
                Window.confirm("For now, it's very easy to remember... you can use both 'j' = 'correct' and 'k' = 'wrong' ");
            }
        });
        helpMenu.addItem("Tutorial", new Command() {

            public void execute() {
                Window.alert("Soon...");
            }
        });
        helpMenu.addItem("The code", new Command() {

            public void execute() {
                Window.open("http://idojava.blogspot.com/2008/09/train-your-brain.html", "Blog", "");               
            }
        });
        mainMenuBar = new MenuBar();
        mainMenuBar.addItem("Game", gameMenu);
        mainMenuBar.addItem("Help", helpMenu);
    }

    private void cleanUI() {
        RootPanel.get().remove(mainPanel);
        RootPanel.get().remove(mainMenuBar);
    }

    /**
     * TODO - add yui
     */
    public void onModuleLoad() {
        createMenuBar();
        mainPanel = new MainPanel();
        
        RootPanel.get().add(mainMenuBar);
        RootPanel.get().add(mainPanel);

    }
}
